// JavaScript Document
function showHome(){
	document.getElementById("select1").style.display="none";
	document.getElementById("select2").style.display="none";
	document.getElementById("select3").style.display="none";
}

function showProvince(){
	document.getElementById("select1").style.display="";
	document.getElementById("select2").style.display="none";
	document.getElementById("select3").style.display="none";
}

function showMunicipal(){
	document.getElementById("select1").style.display="";
	document.getElementById("select2").style.display="";
	document.getElementById("select3").style.display="none";
}

function showClaim(){
	document.getElementById("select1").style.display="";
	document.getElementById("select2").style.display="";
	document.getElementById("select3").style.display="";
	
}

function checkInputData(pig) {		
	var val = pig.value;
	var patrn = new   RegExp("[\|~`!@_,./?=';:[#\$%\^&\*\<\>\{\}()\+\-]+");
	if(!val) {
        return true;
	}
	if (val.match(patrn) == null) {
		return true;
	}  else {
	   pig.value=pig.value.substr(0,pig.value.length-1);
	}	
}

function checkInvalidUser(obj){
	var reg = /^([a-zA-Z0-9]){0,20}$/;
	if(!reg.exec(obj.value)){
		alert("输入字符非法，只能输入20个英文字母或数字，请重新输入。");
		obj.focus();
		return false;
	}
	return true;
}


function disableManager(){
	var admin = document.getElementById("checkbox1").checked;
	var appraiser = document.getElementById("checkbox2").checked;
	var manager = document.getElementById("checkbox3")
	var reinspector = document.getElementById("checkbox4").checked ;
	if(admin||appraiser||reinspector == true){
		manager.disabled = "false";
	}else{
		manager.disabled = "";
	}
	if(reinspector == true){
		document.getElementById("tr_level").style.display="";
	}else{
		document.getElementById("tr_level").style.display="none";
	}
}

function disableAAR(){
	var admin = document.getElementById("checkbox1");
	var appraiser = document.getElementById("checkbox2");
	var manager = document.getElementById("checkbox3").checked;
	var reinspector = document.getElementById("checkbox4");
	if(manager == true){
		admin.disabled = "false";
		appraiser.disabled = "false";
		reinspector.disabled = "false";
	}else{
		admin.disabled = "";
		appraiser.disabled = "";
		reinspector.disabled = "";
	}
}

function addLevel(){
	var levelTable = document.getElementById('levelTable');
	var rowLength = levelTable.rows.length;
	var row = levelTable.insertRow(rowLength);
	row.className="rowEven";
	var cell_1 = row.insertCell(0);
    var cell_2 = row.insertCell(1);
	row.insertCell(2);
	cell_1.vAlign = "top";
	cell_2.vAlign = "top";
	var cell_1_content = "<div align='left'><input name='textfield2' type='text' /></div>";
    var cell_2_content = "<div align='left'> From <input type='text' name='textfield' /> To <input type='text' name='textfield'/></div>";
	cell_1.innerHTML=cell_1_content;
    cell_2.innerHTML=cell_2_content;
}

function deleteLevel(){
	var levelTable = document.getElementById('levelTable');
	var rowLength = levelTable.rows.length;
	if(rowLength > 2){
		levelTable.deleteRow(rowLength - 1);
	}
	
}
var var_companyId = "";
var var_companyLev = 4;
function changeLev(obj){
	var_companyLev = obj.value;	
}
function changeCompanyId(obj){
	var_companyLev = document.editUserProfile.companyLev.value;
	var_companyId = obj.value;
}
function CompanyTree_search_show(data){
	if(!isTimeout(data,true)){
		$('#divCompanyTreeId').html(data);
	}
}
function CompanyTree_search(){
	var url = "ajaxcompanytreesearch.action";  
	var params = {"companyId":var_companyId,"companyLev":var_companyLev}; 
	$.post(url,params,function (data){    
		CompanyTree_search_show(data);
        });
}

function changeSelectOption(){
	var itemradio = document.getElementsByName("companyLev");
	var itemvalue = null;    
    for(i=0;i<itemradio.length;i++){      
        if(itemradio[i].checked){   
            itemvalue = itemradio[i].value; 
        }   
    } 
	var url = "ajaxcompanytreesearch.action";  
	var params = {"companyId":var_companyId,"companyLev":itemvalue}; 
	$.post(url,params,function (data){ 
		if(!isTimeout(data,true)){
		$('#divCompanyTreeId').html(data);
		}
        });
}

var flag=false;
function selectAll(check){
	flag=!flag;
	allCheckBoxSelectTo(flag,document.getElementsByName(check));
} 
function allCheckBoxSelectTo(flag,items){
	if (items.length){
		for (i=0;i<items.length;i++){
			if (items[i].type == "checkbox") {
				items[i].checked = flag ;
			}
		}
	} else {
		if (items.type =="checkbox") {
			items.checked = flag ;
		}
	}
}
function checkSelect(items){
	var count = 0;
	if(items){
		if(items.length){
			for(i=0;i<items.length;i++){
				if(items[i].checked){
					count++;					
				}
			}
		}
		else{
			if(items.checked){
				count = 1;
			}
		}
	}
	return count;
 }

function checkInvalidChar(obj){
	var reg = /^[a-zA-Z0-9]*$/;
	if(!reg.exec(obj.value)){
		alert("输入字符非法，只能输入英文字母和数字，请重新输入。");
		obj.focus();
		return false;
	}
	return true;
}

function checkInputRemark(tt) {		
	var val = tt.value;
	var patrn = new   RegExp("[\~`;'\"\^\*\<\>\]");
	if(!val) {
        return true;
	}
	if (val.match(patrn) == null) {
		return true;
	}  else {
	   tt.value=tt.value.substr(0,tt.value.length-1);
	}	
}

function checkInvalidPwd(obj){
	if(!isPasswordValid(obj.value)){
		alert("输入密码包含非法字符，请重新输入。");
		obj.focus();
		return false;
	}
	if(obj.value.length > 20){
		alert("密码最多20个字符，请重新输入。");
		obj.focus();
		return false;
	}
	if(obj.value.length < 1){
		alert("请输入密码。");
		obj.focus();
		return false;
	}
	return true;
}

function isPasswordValid(val){
    var patrn = new   RegExp("[~`\^\*\<\>;\'\"]+");
	 if(!val) {
	     return true;
	 }
	 if (val.match(patrn) == null) {
	     return true;
	 }  else 
    {
	     return false;
	 }
}